package com.ezops.poc.validations.validators;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class ValidatorHandler implements ApplicationContextAware,
		InitializingBean {

	private ApplicationContext applicationContext;
	
	private static Map<String, String> nameValidatorMapping = new HashMap<>();

	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		this.applicationContext = applicationContext;
	}

	@Override
	public void afterPropertiesSet() throws Exception {

		final Map<String, Object> myFoos = applicationContext
				.getBeansWithAnnotation(Validator.class);

		for (final Object myFoo : myFoos.values()) {
			final Class<? extends Object> fooClass = myFoo.getClass();
			final Validator annotation = fooClass
					.getAnnotation(Validator.class);
			System.out.println("Found validator class: " + fooClass + ", with name: "
					+ annotation.name());
		}
	}

}
